import request from '@/utils/request'
import { CommonSearch } from '@/config/list'
import { StarTreeNode } from '@/model/common/tree/model'
import { UnitList, UnitBeanData } from '@/model/system/unit/model'

export function loadAllUnit () {
  return request<StarTreeNode[]>({
    url: '/starUnit/loadAllUnit',
    method: 'get'
  })
}

export function loadUnitByFid (data: CommonSearch) {
  return request<UnitList>({
    url: '/starUnit/loadUnitByFid',
    data: data,
    method: 'post'
  })
}

export function loadUnitById (id: string) {
  return request<UnitBeanData>({
    url: `/starUnit/loadUnitById?id=${id}`,
    method: 'get'
  })
}

export function deleteUnit (id: string) {
  return request({
    url: `/starUnit/removeUnit?id=${id}`,
    method: 'post'
  })
}

export function saveUnit (formData: UnitBeanData) {
  return request({
    url: '/starUnit/saveUnit',
    data: formData,
    method: 'post'
  })
}

export function getMaxIndex (fid: string) {
  return request<string>({
    url: `/starUnit/getMaxIndex?fid=${fid}`
  })
}
